import { h, defineComponent, type PropType } from 'vue';

export default defineComponent({
  name: 'RenderComponent',
  props: {
    modelValue: {
      type: Object,
    },
    componentName: {
      type: String,
    },
    componentPros: {
      type: Object as PropType<Record<string, unknown>>,
    },
  },
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  render(props: any) {
    const componentName = props.componentName;
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    //@ts-ignore
    const MyComponent = window.app._context.components[componentName];
    const componentPros = props.componentPros as Record<string, unknown>;
    if (MyComponent) {
      return h(MyComponent, {
        ...componentPros,
        modelValue: this.modelValue,
        onInput: (value) => {
          this.$emit('update:modelValue', value);
        },
      });
    }
    return h('div', {}, '无效插件');
  },
});
